﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 投稿列表
	/// </summary>
	[Serializable]
    public class Contribution : IEntity
	{
        public Contribution()
        {
            this.ContributionItems = new List<ContributionItem>();
            this.Comments = new List<Comment>();
        }
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
		/// <summary>
		/// 任务ID
		/// </summary>
        public virtual int TaskId { set; get; }
		/// <summary>
		/// 设计师ID
		/// </summary>
        public virtual int DesignerId { set; get; }
		/// <summary>
		/// 状态
		/// </summary>
        public virtual int Status { set; get; }
        /// <summary>
        /// 设计标题
        /// </summary>
        public virtual string Title { get; set; }
        /// <summary>
        /// 投稿时间
        /// </summary>
        public virtual DateTime CreateTime { get; set; }
        /// <summary>
        /// 评分
        /// </summary>
        public virtual int RankScore { get; set; }
        /// <summary>
        /// 评分说明
        /// </summary>
        public virtual string RankExplain { get; set; }
        /// <summary>
        /// 评分时间
        /// </summary>
        public virtual DateTime? RankTime { get; set; }
        /// <summary>
        /// 是否入围
        /// </summary>
        public virtual bool Finalist{ get;set;}
        /// <summary>
        /// 投稿项
        /// </summary>
        public virtual IList<ContributionItem> ContributionItems { get; set; }
        /// <summary>
        /// 是否已发放酬劳
        /// </summary>
        public virtual bool HasReword { get; set; }
        /// <summary>
        /// 评论
        /// </summary>
        public virtual IList<Comment> Comments { get; set; }
        public virtual User Designer { get; set; }
        public virtual Task Task { get; set; }
        public virtual ContributionStatus ContributionStatus 
        {
            get
            {
                return (ContributionStatus)this.Status;
            }
        }
        public virtual ContributionItem LastItem
        {
            get
            {
                return this.ContributionItems.OrderByDescending(t => t.CreateTime).FirstOrDefault();
            }
        }
        public static MappingConfiguration<Contribution> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<Contribution>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.TaskId,
                t.DesignerId,
                t.Status,
                t.Title,
                t.CreateTime,
                t.RankScore,
                t.RankTime,
                t.Finalist,
                t.RankExplain,
                t.HasReword
            }).ToTable("Contributions");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.Comments).WithOpposite(d=>d.Contribution).HasConstraint((t, d) => t.ID == d.ContributionId);
            return threadMapping;
        }
	}
    public enum ContributionStatus
    { 
        已投稿 = 1,
        修稿中 =2,
        已截稿 =3
    }
}

